# -*- coding: utf-8  -*-
#!/usr/local/bin/python
__author__ = 'jian.yao'

from django.db  import models
from usermanage.account.models import User

class Channel(models.Model):
    name        = models.CharField(max_length=50, null=False, blank=False)
    key         = models.CharField(max_length=100, null=False, blank=False)
    expiration  = models.DateTimeField(null=True, blank=True)
    description = models.CharField(max_length=100, null=True, blank=True)
    domain      = models.CharField(max_length=1024, null=True, blank=True)
    creator     = models.IntegerField(null=False, blank=False)
    create_time = models.DateTimeField(auto_now_add=True)
    last_editor = models.IntegerField(null=False, blank=False)
    last_update = models.DateTimeField(auto_now=True)

class Role(models.Model):
    channel     = models.ForeignKey(Channel, null=False, blank=False)
    name        = models.CharField(max_length=50, null=False, blank=False)
    is_default  = models.BooleanField(default=False, null=False, blank=False)
    description = models.CharField(max_length=100, null=True, blank=True)
    creator     = models.IntegerField(null=False, blank=False)
    create_time = models.DateTimeField(auto_now_add=True)
    last_editor = models.IntegerField(null=False, blank=False)
    last_update = models.DateTimeField(auto_now=True)

class RolePermission(models.Model):
    role        = models.ForeignKey(Role, null=False, blank=False)
    module      = models.IntegerField(null=False, blank=False)
    method      = models.IntegerField(null=False, blank=False)
    last_editor = models.IntegerField(null=False, blank=False)
    last_update = models.DateTimeField(auto_now=True)

class AdminRole(models.Model):
    user        = models.ForeignKey(User, null=False, blank=False)
    role        = models.ForeignKey(Role, null=False, blank=False)
    last_editor = models.IntegerField(null=False, blank=False)
    last_update = models.DateTimeField(auto_now=True)
